package ndfs.tree;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;

public class TreeNode {
	
	
	int hash;
	TreeNode left, right;
	AtomicBoolean red;
	AtomicInteger counter;
	private ReentrantLock lock;

	public TreeNode (int hash) {
		this.hash = hash;
		left = right = null;
		red = new AtomicBoolean();
		counter = new AtomicInteger();
		lock = new ReentrantLock();
	}
	
	
	public TreeNode getLeftChild(){
		return left;
	}
	public void setLeftChild(TreeNode child){
		left = child;
	}
	
	public int getHash(){
		return hash;
	}
	
	public TreeNode getRightChild(){
		return right;
	}
	
	public void setRightChild(TreeNode child){
		right = child;
	}
	
	public boolean getRed(){
		return red.get();
	}
	
	public void setRed(Boolean value){
		red.set(value);
	}
	
	public void incrementCounter(){
		counter.incrementAndGet();
	}
	
	public void decrementCounter(){
		counter.decrementAndGet();
	}
	
	public int getCounter(){
		return counter.get();
	}
	
	
	public void lock() {
		lock.lock();
	}
	
	public void unlock() {
		lock.unlock();
	}
	
}



